package cn.cimoc.service.impl;

import cn.cimoc.mapper.CartMapper;
import cn.cimoc.mapper.ProductMapper;
import cn.cimoc.model.dto.inut.CartInput;
import cn.cimoc.model.dto.output.ProductDTO;
import cn.cimoc.model.dto.output.ProductDetails;
import cn.cimoc.model.po.TCart;
import cn.cimoc.model.po.TProduct;
import cn.cimoc.service.ProductService;
import cn.cimoc.util.CommonUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LGZ
 * @date 2022/7/16 13:57
 * <p>
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper mapper;

    @Override
    public List<ProductDTO> getHot() {
        QueryWrapper<TProduct> wrapper = new QueryWrapper<>();
        wrapper.select("image", "id", "title", "price");
        List<TProduct> data = mapper.selectList(wrapper);
        return CommonUtils.getMapperFacade().mapAsList(data, ProductDTO.class);
    }

    @Override
    public ProductDetails getDetails(long id) {
        QueryWrapper<TProduct> wrapper = new QueryWrapper<>();
        wrapper.select("image", "sell_point", "title", "price")
                .eq("id", id);
        TProduct data = mapper.selectOne(wrapper);
        return CommonUtils.getMapperFacade().map(data, ProductDetails.class);
    }

}
